﻿//
// *************************************************************************************
// WP-Framework
// 
// Developed by
// Lukas Kretschmar (lkretschmar.dev@bluewin.ch)
//
// Switzerland, Copyright (c) 2013 lkretschmar
// This content is released under the MIT License (http://opensource.org/licenses/MIT).
//     
// *************************************************************************************
//
//


using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using KretschIT.WP_Fx.EasyMoq.Generator.Items;
using KretschIT.WP_Fx.EasyMoq.Generator.Tests.Helpers.Inheritance;

namespace KretschIT.WP_Fx.EasyMoq.Generator.Tests.Items
{
    [TestClass]
    public class ClassAnalyzerTest
    {
        private IClassAnalyzer analyzer;

        [TestInitialize]
        public void Init()
        {
            this.analyzer = new ClassAnalyzer();
        }


        [TestMethod]
        public void Test_GetEventsOfType()
        {
            var type = typeof(ITop);
            var events = this.analyzer.GetEventsOf(type);
            Assert.AreEqual(2, events.Count());
        }

        [TestMethod]
        public void Test_GetEventsOfType_Overrloaded()
        {
            var type = typeof(ITopOverload);
            var events = this.analyzer.GetEventsOf(type);
            Assert.AreEqual(1, events.Count());
        }

        [TestMethod]
        public void Test_GetMethodsOfType()
        {
            var type = typeof(ITop);
            var methods = this.analyzer.GetMethodsOf(type);
            Assert.AreEqual(2, methods.Count());
        }

        [TestMethod]
        public void Test_GetMethodsOfType_Overloaded()
        {
            var type = typeof(ITopOverload);
            var methods = this.analyzer.GetMethodsOf(type);
            Assert.AreEqual(1, methods.Count());
        }

        [TestMethod]
        public void Test_GetPropertiesOfType()
        {
            var type = typeof(ITop);
            var properties = this.analyzer.GetPropertiesOf(type);
            Assert.AreEqual(2, properties.Count());
        }

        [TestMethod]
        public void Test_GetPropertiesOfType_Overloaded()
        {
            var type = typeof(ITopOverload);
            var properties = this.analyzer.GetPropertiesOf(type);
            Assert.AreEqual(1, properties.Count());
            var p = properties.Single();
            Assert.IsTrue(p.CanRead);
            Assert.IsTrue(p.CanWrite);
        }

        [TestMethod]
        public void Test_GetPropertiesOfType_Overlapping()
        {
            var type = typeof (ISetter);
            var types = this.analyzer.GetPropertiesOf(type);
            Assert.AreEqual(2, types.Count());
            Assert.IsTrue(types.First().CanWrite);
            Assert.IsTrue(types.Last().CanRead);
        }

        [TestMethod]
        public void Test_GetPropertiesOfType_Overlapping_OtherHierarchy()
        {
            var type = typeof(IOtherGetter);
            var types = this.analyzer.GetPropertiesOf(type);
            Assert.AreEqual(2, types.Count());
            Assert.IsTrue(types.First().CanRead);
            Assert.IsTrue(types.Last().CanWrite);
        }
    }
}
